<template>
<view>
<form @reset="formReset" @submit="release" reportSubmit="true">
    <view class="body">
        <view class="modle">
      卖车地点
      <input class="modle_right" name="address" placeholder="请输入卖车地点" placeholderStyle="color: #9295A8;" type="text">
        </view>
        <view class="modle">
      品牌车型
      <input class="modle_right" name="cartype" placeholder="请输入品牌车型" placeholderStyle="color: #9295A8;" type="text">
        </view>
        <view class="modle">
      上牌时间
      <picker @change="bindDateChange" class="modle_right" mode="date" :value="date">
                <view class="picker">
          {{date}}
        </view>
            </picker>
        </view>
        <view class="modle">
      行驶里程（万公里）
      <input class="modle_right" name="licheng" placeholder="请输入行驶里程" style="width:300rpx;">
        </view>
        <view class="modle">
      联系方式
      <button @getphonenumber="getPhoneNumber" class="shouquan_btn" open-type="getPhoneNumber">电话授权</button>
            <input class="modle_right" name="phone" placeholder="请输入您的电话" style="margin-right:20rpx;width:300rpx;" :value="userphone">
        </view>
        <view class="modle" style="border-bottom:0">
      车辆详图
    </view>
        <view class="shop_view_border">
            <view v-for="(item, index) in carsimgs" :key="index" class="shop_view" v-if="item.img!=''">
                <image @tap="upthiscarsimgs" class="shop_view_closeimg" :data-index="index" src="/static/pages/image/tupiangb_btn.png"></image>
                <image @tap="showimgs" class="shop_view_img" :data-index="index" :src="item.img"></image>
            </view>
            <view class="shop_view" v-if="carsimgs.length<3">
                <image @tap="upcarsimgs" class="shop_view_img" src="/static/pages/image/tianjiantp_btn.png"></image>
            </view>
        </view>
    </view>
    <button class="commit_btn" form-type="submit">估算价格</button>
</form>
<!--<import src="/pages/alert/index.wxml"></import>-->
<block data-type="template" data-is="alert" data-attr="isShow:isShow">
    <view class="wx_dialog_container" :hidden="!isShow">
        <view class="wx-alert-mask"></view>
        <view class="wx-alert-dialog">
            <view class="wx-alert-dialog-title">尊敬的用户</view>
            <view class="wx-alert-dialog-content">尚未获取到您的用户信息，较多功能无法体验，请允许获取用户信息</view>
            <view class="wx-alert-dialog-footer">
                <button @tap="hideDialog" class="wx-alert-dialog-btn">拒绝</button>
                <button @getuserinfo="updateUserInfo" class="wx-alert-dialog-btn" open-type="getUserInfo">允许</button>
            </view>
        </view>
    </view>
</block>
</view>
</template>

<script>
var app = getApp();

export default {
  data() {
    return {
      isShow: !1,
      buttscan: !1,
      date: "请选择时间",
      address: "",
      cartype: "",
      licheng: "",
      userphone: "",
      carsimgs: []
    };
  },

  components: {},
  props: {},
  onLoad: function (t) {},
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {},
  onShareAppMessage: function () {},
  methods: {
    release: function (t) {
      var a = this,
          e = wx.getStorageSync("uid");

      if (e) {
        if (!a.buttscan) {
          a.setData({
            buttscan: !0
          });
          var i = t.detail.value.address;
          if ("" == i || "undefined" == i || "请输入卖车地点" == i) return app.globalData.util.message({
            title: "请输入卖车地点",
            type: "error"
          }), void a.setData({
            buttscan: !1
          });
          var s = t.detail.value.cartype;
          if ("" == s || "undefined" == s || "请输入品牌车型" == s) return app.globalData.util.message({
            title: "请输入品牌车型",
            type: "error"
          }), void a.setData({
            buttscan: !1
          });
          var n = a.date;
          if ("请选择时间" == n || "undefined" == n || "" == n) return app.globalData.util.message({
            title: "请选择上牌时间",
            type: "error"
          }), void a.setData({
            buttscan: !1
          });
          var r = t.detail.value.licheng;
          if ("" == r || "undefined" == r || "请输入行驶里程" == r) return app.globalData.util.message({
            title: "请输入行驶里程",
            type: "error"
          }), void a.setData({
            buttscan: !1
          });
          var o = t.detail.value.phone;
          if ("" == o || "undefined" == o) return app.globalData.util.message({
            title: "请填写联系电话，或点击电话授权",
            type: "error"
          }), void a.setData({
            buttscan: !1
          });
          var u = a.carsimgs;
          if (u.length < 1) return app.globalData.util.message({
            title: "请至少添加1个车辆图片",
            type: "error"
          }), void a.setData({
            buttscan: !1
          });
          var c = [];

          for (var d in u) "" != u[d].imgshort && "" != u[d].img && (console.log(u[d]), console.log(u[d].imgshort), c.push(u[d]));

          var l = {
            r: "sale.index.ingujia",
            m: "monai_market",
            fomid: t.detail.formId,
            uid: e,
            address: i,
            topdate: n,
            cartype: s,
            phone: o,
            licheng: r,
            carimages: c
          };
          app.globalData.util.request({
            url: "entry/wxapp/Api",
            data: l,
            cachetime: "0",
            success: function (t) {
              200 == t.data.message ? wx.showToast({
                title: "提交成功",
                icon: "success",
                duration: 2e3
              }) : (console.log(t.data), wx.showToast({
                title: "提交失败请稍后再试",
                icon: "none",
                duration: 2e3
              })), a.setData({
                buttscan: !1
              });
            },
            fail: function (t) {
              a.setData({
                buttscan: !1
              });
            }
          });
        }
      } else a.setData({
        isShow: !0
      });
    },
    getPhoneNumber: function (t) {
      console.log(t);
      var a = this;
      app.globalData.util.request({
        url: "entry/wxapp/Api",
        data: {
          r: "sale.index.userphone",
          m: "monai_market",
          iv: t.detail.iv,
          encryptedData: t.detail.encryptedData
        },
        cachetime: "0",
        success: function (t) {
          a.setData({
            userphone: t.data.data
          });
        }
      });
    },
    upcarsimgs: function (t) {
      var e = this;
      3 <= e.carsimgs.length ? app.globalData.util.message({
        title: "您添加的图片已经很多了",
        type: "error"
      }) : app.globalData.upimgs({
        scannums: 3,
        filename: "cars",
        success: function (t) {
          for (var a in t) e.addinimgs(t[a]);
        }
      });
    },
    addinimgs: function (t) {
      var a = this.carsimgs,
          e = {
        img: t.all,
        imgshort: t.short
      };
      a.push(e), this.setData({
        carsimgs: a
      });
    },
    showimgs: function (t) {
      var a = t.currentTarget.dataset.index,
          e = this.carsimgs;
      wx.previewImage({
        current: e[a].img,
        urls: [e[a].img]
      });
    },
    upthiscarsimgs: function (t) {
      var a = t.currentTarget.dataset.index,
          e = this.carsimgs;
      app.globalData.util.request({
        url: "entry/wxapp/Api",
        data: {
          m: "monai_sharing",
          uid: app.globalData.getuid(),
          imgurl: e[a].img,
          r: "Upimg.delImg"
        }
      }), e.splice(a, 1), this.setData({
        carsimgs: e
      });
    },
    bindDateChange: function (t) {
      console.log("picker发送选择改变，携带值为", t.detail.value), this.setData({
        date: t.detail.value
      });
    },

    formReset() {
      console.log("占位：函数 formReset 未声明");
    }

  }
};
</script>
<style>
@import "./index.css";
</style>